<template>
  <a-config-provider :locale="locale">
    <div id="app">
      <router-view />
    </div>
  </a-config-provider>
</template>
<script>
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN' //中文
import enUS from 'ant-design-vue/lib/locale-provider/en_US' //英语
import esES from 'ant-design-vue/lib/locale-provider/es_ES' //西班牙语
import frFR from 'ant-design-vue/lib/locale-provider/fr_FR' //法语
import ruRU from 'ant-design-vue/lib/locale-provider/ru_RU' //俄罗斯语
import arEG from 'ant-design-vue/lib/locale-provider/ar_EG' //阿拉伯语
import zhTW from 'ant-design-vue/lib/locale-provider/zh_TW' //中文繁体
import thTH from 'ant-design-vue/lib/locale-provider/th_TH' //泰语
import viVN from 'ant-design-vue/lib/locale-provider/vi_VN' //越南语
import heIL from 'ant-design-vue/lib/locale-provider/he_IL' //希伯来语
import msMY from 'ant-design-vue/lib/locale-provider/ms_MY' //马来语（马来西亚）
import idID from 'ant-design-vue/lib/locale-provider/id_ID' //印度尼西亚语
import enquireScreen from '@/utils/device'
let locale = {
  zh_TW: zhTW,
  zh_CN: zhCN,
  en_US: enUS,
  es_ES: esES,
  fr_FR: frFR,
  ru_RU: ruRU,
  ar_EG: arEG,
  th_TH: thTH,
  vi_VN: viVN,
  he_IL: heIL,
  ms_MY: msMY,
  id_ID: idID
}
export default {
  data() {
    return {
      locale: locale[localStorage.getItem('language')],
      gap_time: 0,
      beforeUnload_time: 0,
    }
  },
  created() {
    let that = this
    if (localStorage.getItem('language') != 'zh_CN') {
      document.body.classList.toggle('font')
    }
    enquireScreen((deviceType) => {
      // tablet
      if (deviceType === 0) {
        that.$store.commit('TOGGLE_DEVICE', 'mobile')
        that.$store.dispatch('setSidebar', false)
      }
      // mobile
      else if (deviceType === 1) {
        that.$store.commit('TOGGLE_DEVICE', 'mobile')
        that.$store.dispatch('setSidebar', false)
      } else {
        that.$store.commit('TOGGLE_DEVICE', 'desktop')
        that.$store.dispatch('setSidebar', true)
      }
    })
  },
  methods: {
    // 关闭窗口之前执行
    beforeunloadHandler() {
      this.beforeUnload_time = new Date().getTime()
    },
    unloadHandler() {
      this.gap_time = new Date().getTime() - this.beforeUnload_time
      //判断是窗口关闭还是刷新 毫秒数判断
      if (this.gap_time <= 10) {
        this.$store.dispatch('Logout')
      }
    },
  },
  unmounted() {
    //vue可换为destroyed()生命周期，不过这个也可以用
    // 移除监听
    window.removeEventListener('beforeunload', () => this.beforeunloadHandler())
    window.removeEventListener('unload', () => this.unloadHandler())
  },
  mounted() {
    // 监听浏览器关闭
    window.addEventListener('beforeunload', () => this.beforeunloadHandler())
    window.addEventListener('unload', () => this.unloadHandler())
  },
}
</script>
<style>
#app {
  height: 100%;
}
body.font{
  font-family: Calibri;
}
.ant-input-number .ant-input-number-input{
  padding: 0 5px
}
#printContent,
#printContent .ant-table,
#printContent .ant-table-thead > tr > th {
  font-family: '黑体', '微软雅黑', '宋体', serif;
  color: #000;
}

#printContent .ant-table-bordered .ant-table-header > table,
#printContent .ant-table-bordered .ant-table-body > table,
#printContent .ant-table-bordered .ant-table-fixed-left table,
#printContent .ant-table-bordered .ant-table-fixed-right table {
  border-collapse: collapse;
}
#printContent .ant-table-bordered .ant-table-header > table,
#printContent .ant-table-bordered .ant-table-body > table,
#printContent .ant-table-bordered .ant-table-fixed-left table,
#printContent .ant-table-bordered .ant-table-fixed-right table,
#printContent .ant-table-bordered .ant-table-thead > tr > th,
#printContent .ant-table-bordered .ant-table-tbody > tr > td,
#printContent .ant-table-bordered.ant-table-empty .ant-table-placeholder,
#printContent .ant-table-placeholder {
  border: 1px solid #000;
}

#printContent .ant-table-middle > .ant-table-content > .ant-table-header > table > .ant-table-thead > tr > th,
#printContent .ant-table-middle > .ant-table-content > .ant-table-body > table > .ant-table-thead > tr > th,
#printContent
  .ant-table-middle
  > .ant-table-content
  > .ant-table-scroll
  > .ant-table-header
  > table
  > .ant-table-thead
  > tr
  > th,
#printContent
  .ant-table-middle
  > .ant-table-content
  > .ant-table-scroll
  > .ant-table-body
  > table
  > .ant-table-thead
  > tr
  > th,
#printContent
  .ant-table-middle
  > .ant-table-content
  > .ant-table-fixed-left
  > .ant-table-header
  > table
  > .ant-table-thead
  > tr
  > th,
#printContent
  .ant-table-middle
  > .ant-table-content
  > .ant-table-fixed-right
  > .ant-table-header
  > table
  > .ant-table-thead
  > tr
  > th,
#printContent
  .ant-table-middle
  > .ant-table-content
  > .ant-table-fixed-left
  > .ant-table-body-outer
  > .ant-table-body-inner
  > table
  > .ant-table-thead
  > tr
  > th,
#printContent
  .ant-table-middle
  > .ant-table-content
  > .ant-table-fixed-right
  > .ant-table-body-outer
  > .ant-table-body-inner
  > table
  > .ant-table-thead
  > tr
  > th,
#printContent .ant-table-middle > .ant-table-content > .ant-table-header > table > .ant-table-tbody > tr > td,
#printContent .ant-table-middle > .ant-table-content > .ant-table-body > table > .ant-table-tbody > tr > td,
#printContent
  .ant-table-middle
  > .ant-table-content
  > .ant-table-scroll
  > .ant-table-header
  > table
  > .ant-table-tbody
  > tr
  > td,
#printContent
  .ant-table-middle
  > .ant-table-content
  > .ant-table-scroll
  > .ant-table-body
  > table
  > .ant-table-tbody
  > tr
  > td,
#printContent
  .ant-table-middle
  > .ant-table-content
  > .ant-table-fixed-left
  > .ant-table-header
  > table
  > .ant-table-tbody
  > tr
  > td,
#printContent
  .ant-table-middle
  > .ant-table-content
  > .ant-table-fixed-right
  > .ant-table-header
  > table
  > .ant-table-tbody
  > tr
  > td,
#printContent
  .ant-table-middle
  > .ant-table-content
  > .ant-table-fixed-left
  > .ant-table-body-outer
  > .ant-table-body-inner
  > table
  > .ant-table-tbody
  > tr
  > td,
#printContent
  .ant-table-middle
  > .ant-table-content
  > .ant-table-fixed-right
  > .ant-table-body-outer
  > .ant-table-body-inner
  > table
  > .ant-table-tbody
  > tr
  > td {
  padding: 0px 2px;
}

@page {
  size: auto;
  margin: 0 3mm;
}
@media print {
  html {
    background-color: #fff;
    height: auto;
    margin: 0px;
  }
  body {
    border: 1px solid #fff;
    margin: 0;
  }
  #printContent,
  #printContent .ant-table,
  #printContent .ant-table-thead > tr > th {
    font-family: '黑体', '微软雅黑', '宋体', serif;
    color: #000;
  }
  #printContent .ant-table-bordered .ant-table-header > table,
  #printContent .ant-table-bordered .ant-table-body > table,
  #printContent .ant-table-bordered .ant-table-fixed-left table,
  #printContent .ant-table-bordered .ant-table-fixed-right table,
  #printContent .ant-table-bordered .ant-table-thead > tr > th,
  #printContent .ant-table-bordered .ant-table-tbody > tr > td {
    border-color: 1px solid #000;
  }

  #printContent .ant-table-bordered .ant-table-header > table,
  #printContent .ant-table-bordered .ant-table-body > table,
  #printContent .ant-table-bordered .ant-table-fixed-left table,
  #printContent .ant-table-bordered .ant-table-fixed-right table {
    border-collapse: collapse;
  }
}

.customTable .ant-table-thead > tr > th,
.customTable .ant-table-tbody > tr > td {
  padding: 8px 8px;
}
.ant-form-item .ant-form-item-label{
  /* white-space: break-spaces;
  word-break: break-word;
  overflow-wrap: break-word; */
}
</style>